package com.direct.web.action;

import com.direct.common.ActionUtils;
import com.direct.common.Utils;
import com.direct.domian.Account;
import com.direct.exception.LoginEXception;
import com.direct.service.AccountService;
import com.direct.service.RoleService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

public class AccountAction extends BaseAction implements
		ModelDriven<Account> {
	
	
	private Account account = new Account();
	
	private AccountService accountService;
	private RoleService roleService;
	//登录方法
	public String login() {
		try {
			//查询员工
			Account dbAccount = accountService.querySingle(account);
			//如果员工不为空,将员工保存到session中
			if(dbAccount!=null){
				getSession().put("current", dbAccount);
			}
		} catch (LoginEXception e) {
			addFieldError("account", e.getMsg());
			return Action.INPUT;
		}
		return Action.SUCCESS;
	}
	//登录校验校验
	public void validateLogin() {
		super.validate();
		if (!Utils.notEmpty(account.getUsername())) {
			addFieldError("username", "请输入用户名");
		}
		if (!Utils.notEmpty(account.getPassword())) {
			addFieldError("password", "请输入密码");
		}
	}

	public Account getAccount() {
		return account;
	}

	public AccountService getAccountService() {
		return accountService;
	}

	@Override
	public Account getModel() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}
	public RoleService getRoleService() {
		return roleService;
	}
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	

}
